﻿namespace LinesOfAction.Converters
{
    using System;
    using System.Globalization;
    using System.Linq;
    using System.Windows.Data;
    using System.Windows.Markup;
    using System.Windows.Media;

    public class PositionToColorConverter : MarkupExtension, IMultiValueConverter
    {
        public PositionToColorConverter()
        {
            
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }

        #region Implementation of IMultiValueConverter

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var colorBrush = new SolidColorBrush {Color = Color.FromRgb(209, 140, 71)};

            var row = values.Cast<int>().First();
            var column = values.Cast<int>().Last();

            if ((row + column)%2 == 0)
                colorBrush.Color = Color.FromRgb(255, 209, 158);

            return colorBrush;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}